package edu.zut.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class PageJumpServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //进行资源（页面、servlet）的跳转

        //转发到newPage.html
        //转发器
//        RequestDispatcher dispatcher = request.getRequestDispatcher("/html/newPage.html");
        //再去调用内部转发
//        dispatcher.forward(request, response);
        //重定向newPage.html
//        response.sendRedirect(request.getContextPath() + "/html/newPage.html");

        //转发到showDateServlet资源   服务器内部资源的跳转  共享request以及response对象的
        //往request对象中保存一些自定义的信息   key-value  key:String  value:Object
        request.setAttribute("myName","jack");
        RequestDispatcher dispatcher = request.getRequestDispatcher("/showDate");
        dispatcher.forward(request,response);
    }
}
